#include "Resources.h"
#include "Sound.h"
#include "SoundManager.h"

#include <string>

#include "ogg/ogg.h"
#include "vorbis/codec.h"
#include "vorbis/vorbisfile.h"

#pragma once

namespace UniverseSound
{
	class StreamedSound : public SoundClip
	{
	public:
		void open(Ogre::DataStreamPtr& fileStream);
		void release();
		void stop();
		void setSource(ALuint& source);
		void pause();
		void play();
		void setPlayPosition(Ogre::Real seconds);

	protected:
		StreamedSound(const Ogre::String& name);
		~StreamedSound();

		bool _stream(ALuint buffer);
		void _updateAudioBuffers();
		void _dequeue();
		void _prebuffer();
		bool _queryBufferInfo();
		void _updatePlayPosition();

	private:
		void _release();

		OggVorbis_File mOggStream;
		vorbis_info *mVorbisInfo;
		vorbis_comment *mVorbisComment;
		ALuint mBuffers[NUM_BUFFERS];
		ALenum mFormat;
		bool mStreamEOF;

		friend class SoundManager;
	};
}